// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.

// Package gmd5 provides useful API for MD5 encryption algorithms.
package cmd5

import (
	"crypto/md5"
	"fmt"
)

// string md5
func EncryptString(data string) (encrypt string, err error) {
	return EncryptBytes([]byte(data))
}

// must string md5
func MustEncryptString(data string) string {
	str, err := EncryptBytes([]byte(data))
	if err != nil {
		panic(err)
	}

	return str
}


// []byte　md5
func EncryptBytes(data []byte) (encrypt string, err error) {
	h := md5.New()
	if _, err = h.Write([]byte(data)); err != nil {
		return "", err
	}
	return fmt.Sprintf("%x", h.Sum(nil)), nil
}



